package GUI.frame;

import GUI.pojo.UserDO;
import GUI.util.Utilimg;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class Text2 extends JFrame {
    private ArrayList<UserDO> list;
    private LoginPanel loginPanel = new LoginPanel(this);//把ATM机分别传入几个卡片里，就可以调用到ATM机里的属性和方法
    private MenuPanel menuPanel = new MenuPanel(this);
    private CunPanel cunPanel = new CunPanel(this);
    private QuPanel quPanel = new QuPanel(this);
    private ChaPanel chaPanel = new ChaPanel(this);
    private GaiPanel gaiPanel = new GaiPanel(this);
    private ZhuanPanel zhuanPanel = new ZhuanPanel(this);
    private Image bgimg = Utilimg.getImage("/img/background.jpg");
    private Image imageIcon = Utilimg.getImage("/img/icon.png");
    private UserDO loginUser;//作为一个对象属性
    public static final String PATH="User.dat";

    public CunPanel getCunPanel() {
        return cunPanel;
    }

    public QuPanel getQuPanel() {
        return quPanel;
    }

    public ChaPanel getChaPanel() {
        return chaPanel;
    }

    public GaiPanel getGaiPanel() {
        return gaiPanel;
    }

    public ZhuanPanel getZhuanPanel() {
        return zhuanPanel;
    }

    private CardLayout cardLayout = new CardLayout();


    public UserDO getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(UserDO loginUser) {
        this.loginUser = loginUser;
    }


    public ArrayList<UserDO> getList() {
        return list;
    }

    public void setList(ArrayList<UserDO> list) {
        this.list = list;
    }

    public Text2() {
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimg, 0, 0, 800, 600, this);
            }
        });
        this.setLayout(cardLayout);
        this.setIconImage(imageIcon);
        this.setTitle("登录");


        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("cun", cunPanel);
        this.add("qu", quPanel);
        this.add("cha", chaPanel);
        this.add("gai", gaiPanel);
        this.add("zhuan", zhuanPanel);


        this.setSize(800, 600);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }
//    //用户初始化
//    public void init() {
//        list=(ArrayList<User>)Util.readObject(PATH);
//        if(list==null){
//            list=new ArrayList<>();
//            list.add(new User("aaa", "111", 1000));
//            list.add(new User("bbb", "222", 500));
//            list.add(new User("ccc", "333", 800));
//            list.add(new User("ddd", "444", 900));
//            list.add(new User("eee", "555", 1200));
//        }
//    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    public static void main(String[] args) {
       new Text2();

    }
}
